home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!nickh
- From: nickh@netcom.com (Nick Huang)
- Subject: MS VC4.0 having problem with friendship + inheritance?
- Message-ID: <nickhDpq1xL.IC4@netcom.com>
- Keywords: friend, inheritance
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- Date: Thu, 11 Apr 1996 23:44:09 GMT
- Sender: nickh@netcom17.netcom.com
-
- I run into problem with the following program with
- MS VC4.0 (VC2.0 runs fine), which says one of the
- statement is ambiguous. Do you think it's
- my problem or the compiler's problem?
-
- Thanks a lot.
-
- Nick
-
- nickh@netcom.com
-
- == test.hpp and test.cpp
-
- // test.hpp
-
- template <class T> class Base {
- protected:
- T Babe;
- public:
- Base();
- Base(T);
-
- friend int operator == (Base<T>&, Base<T>&);
- operator != (Base<T>&);
- };
-
- template <class T> class Array : public Base<T> {
- protected:
- T Val;
- public:
- Array();
- Array(T);
-
- friend int operator == (Array<T>&, Array<T>&);
- operator != (Array<T>&);
- };
-
- // test.cpp
-
- #include <stdio.h>
-
- #include "test.hpp"
-
- // Base
- template<class T> int operator == (Base<T>& x, Base<T>& y)
- {
- return x.Babe == y.Babe;
- }
-
- template<class T> int Base<T>::operator != (Base<T>& x)
- {
- return this->Babe != x.Babe;
- }
-
- template<class T> Base<T>::Base(T x)
- {
- Babe = x;
- }
-
- template<class T> Base<T>::Base()
- {
-
- }
-
- // Array
-
- template<class T> int operator == (Array<T>& x, Array<T>& y)
- {
- return x.Val == y.Val;
- }
-
- template<class T> int Array<T>::operator != (Array<T>& x)
- {
- return this->Val != x.Val;
- }
-
- template<class T> Array<T>::Array(T x)
- {
- Val = x;
- }
-
- template<class T> Array<T>::Array()
- {
-
- }
-
- main()
- {
- Base<int> m(3), n(2);
- Array<int> x(3), y(2), a(4), b(4);
-
- if (m != n) printf("base not eq.\n");
- if (x != y) printf("hello.\n");
- if (a == b) printf("hello again\n"); // MSVC4.0 says this is ambiguous!!
- return 0;
- }
-